package com.example.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.example.pojo.jobDescriptionPojo;
import com.example.pojo.standardWorkListPojo;
import com.example.pojo.taskListDataPojo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * ClassName:jobDescriptionMapp
 * Description:
 *
 * @Author 赵永峰
 * @Create 2024/9/11 23:46
 * @Version 1.0
 */
@Mapper
public interface jobDescriptionMapp {
    @DS("baodingRussia")
    @Insert("insert into jobDescription " +
            "(positionChinese, positionEnglish, positionRussian, " +
            "jobItem, cycle, completionDate, " +
            "jobCategory, usageTime, sectionName, " +
            "departmentName, companyName, jobSource, " +
            "sourceRecord, workBook, endRecord, " +
            "establishTime, updateTime,head," +
            "deleteSign) " +
            "VALUES " +
            "(#{positionChinese},#{positionEnglish},#{positionRussian}," +
            "#{jobItem},#{cycle},#{completionDate}," +
            "#{jobCategory},#{usageTime},#{sectionName}," +
            "#{departmentName},#{companyName},#{jobSource}," +
            "#{sourceRecord},#{workBook},#{endRecord}," +
            "#{establishTime},#{updateTime},#{head}," +
            "#{deleteSign})")
    void insertOne(jobDescriptionPojo jobDescriptionPojo);
    //依据三个字段查询数据，字段是字符串类型
    @DS("baodingRussia")
    @Select("select * from jobDescription where ${fieldOne}=#{fieldOneVal} and ${fieldTwo}=#{fieldTwoVal} and ${fieldThree}=#{fieldThreeVal} and deleteSign=1")
    List<jobDescriptionPojo> queryAllByThreeStr(String fieldOne, String fieldOneVal, String fieldTwo, String fieldTwoVal, String fieldThree, String fieldThreeVal);
    //依据id，修改一行数据
    @DS("baodingRussia")
    @Update("update jobDescription " +
            "set " +
            "jobItem=#{jobItem}," +
            "cycle=#{cycle}," +
            "completionDate=#{completionDate}," +
            "jobSource=#{jobSource}," +
            "sourceRecord=#{sourceRecord}," +
            "usageTime=#{usageTime}," +
            "jobCategory=#{jobCategory}," +
            "head=#{head}," +
            "updateTime=#{updateTime} " +
            "where id=#{id}")
    void editOne(jobDescriptionPojo jobDescriptionPojo);
    //根据id，删除一行数据
    @DS("baodingRussia")
    @Update("update jobDescription set deleteSign=0,updateTime=#{updateTime} where id=#{id}")
    void deleteOnebyId(jobDescriptionPojo jobDescriptionPojo);
    //对标准工作，插入一行数据
    @DS("newMscLowCodeFormal")
    @Insert("insert into standard_work_list (" +
            "establishTime, updateTime, deleteSign, " +
            "editName, projectName, projectDes, " +
            "projectTime, projectType, position) " +
            "VALUES " +
            "(#{establishTime}, #{updateTime}, #{deleteSign}, " +
            "#{editName}, #{projectName}, #{projectDes}, " +
            "#{projectTime}, #{projectType}, #{position})")
    void insertStandardWorkList(standardWorkListPojo standardWorkListPojo);
    //辅助函数，对标准工作中，查询出所有数据
    @DS("newMscLowCodeFormal")
    @Select("select * from standard_work_list where deleteSign=1")
    List<standardWorkListPojo> inquiryStandardWorkListAll();
    //辅助函数，对标准工作中，根据ID，修改一行数据,修改所有数据
    @DS("newMscLowCodeFormal")
    @Update("update standard_work_list set " +
            "establishTime = #{establishTime}, " +
            "updateTime = #{updateTime}, " +
            "deleteSign = #{deleteSign}, " +
            "editName = #{editName}, " +
            "projectName = #{projectName}, " +
            "projectDes = #{projectDes}, " +
            "projectTime = #{projectTime}, " +
            "projectType = #{projectType}, " +
            "position = #{position} " +
            "WHERE id = #{id}")
    void upDataStandardWorkList(standardWorkListPojo pojo);
    //辅助函数，对课题中插入一行
    @DS("newMscLowCodeFormal")
    @Insert("INSERT INTO task_list_data (" +
            "establishTime, " +          // 对应Java字段：establishTime
            "updateTime, " +             // 对应Java字段：updateTime
            "deleteSign, " +             // 对应Java字段：deleteSign
            "editName, " +               // 对应Java字段：editName
            "taskName, " +               // 对应Java字段：taskName
            "description, " +             // 对应Java字段：description
            "startDate, " +              // 对应Java字段：startDate
            "planEndDate, " +           // 对应Java字段：planEndDate（注意原代码中的planEndData拼写错误）
            "plan, " +                    // 对应Java字段：plan
            "progress, " +                // 对应Java字段：progress
            "userComment, " +            // 对应Java字段：userComment
            "actualEndDate, " +         // 对应Java字段：actualEndDate（注意原代码中的actualEndData拼写错误）
            "difficulty, " +              // 对应Java字段：difficulty
            "score, " +                   // 对应Java字段：score
            "feedback, " +                // 对应Java字段：feedback
            "creator, " +                 // 对应Java字段：creator
            "manager, " +                 // 对应Java字段：manager
            "managerId, " +              // 需确认数据库是否存在该字段
            "creatorId," +                // 需确认数据库是否存在该字段
            "isFinish"+
            ") VALUES (" +
            "#{establishTime}, " +
            "#{updateTime}, " +
            "#{deleteSign}, " +
            "#{editName}, " +
            "#{taskName}, " +
            "#{description}, " +
            "#{startDate}, " +
            "#{planEndDate}, " +
            "#{plan}, " +
            "#{progress}, " +
            "#{userComment}, " +
            "#{actualEndDate}, " +
            "#{difficulty}, " +
            "#{score}, " +
            "#{feedback}, " +
            "#{creator}, " +
            "#{manager}, " +
            "#{managerId}, " +
            "#{creatorId}," +
            "#{isFinish}" +
            ")")
    void insertTaskList(taskListDataPojo pojo);
    //辅助函数，对课题中筛选出所有的数据
    @DS("newMscLowCodeFormal")
    @Select("select * from task_list_data where deleteSign=1 order by startDate DESC ")
    List<taskListDataPojo> inquiryTaskListAll();
    //辅助函数，对课题中插入一行,修改所有的内容
    @DS("newMscLowCodeFormal")
    @Update("UPDATE task_list_data " +
            "SET " +
            "establishTime = #{establishTime}, " +          // 创建时间
            "updateTime = #{updateTime}, " +                // 更新时间（会自动覆盖）
            "deleteSign = #{deleteSign}, " +                // 删除标记
            "editName = #{editName}, " +                    // 编辑人
            "taskName = #{taskName}, " +                    // 课题名称
            "description = #{description}, " +               // 课题描述
            "startDate = #{startDate}, " +                  // 开始时间
            "planEndDate = #{planEndDate}, " +             // 计划完成日期
            "plan = #{plan}, " +                             // 工作计划
            "progress = #{progress}, " +                     // 工作进展
            "userComment = #{userComment}, " +              // 留言
            "actualEndDate = #{actualEndDate}, " +         // 实际完成日期
            "difficulty = #{difficulty}, " +                 // 难易程度
            "score = #{score}, " +                           // 得分
            "feedback = #{feedback}, " +                     // 评价
            "creator = #{creator}, " +                       // 创建人
            "manager = #{manager}, " +                       // 负责人
            "managerId = #{managerId}, " +                  // 负责人ID
            "creatorId = #{creatorId}, " +                  // 创建人ID
            "isFinish = #{isFinish} " +                     // 完成状态（新增字段）
            "WHERE id = #{id} " )                          // ✅ 必须包含id条件

    void upDataTaskList(taskListDataPojo pojo);
}